﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ChuyenKhoan : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int userid = -1;
        try
        {
            userid = Convert.ToInt32(Session["userid"]);
        }
        catch (Exception)
        {
            userid = -1;
            Session["userid"] = -1;
        }
        if (userid <= 0)
        {
            Response.Redirect("~/login.aspx");
        }
        if (!Page.IsPostBack)
        {
            Bank.Balance _balance = new Bank.Balance();
            Label3.Text = _balance.getBalanceInfo(userid).Tables[0].Rows[0]["BalanceUSD"].ToString();
            MultiView1.ActiveViewIndex = 0;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Bank.Balance _balance = new Bank.Balance();
        int senderid = Convert.ToInt32(Session["userid"]);
        string password = TextBox3.Text;
        string receivername = TextBox1.Text;
        int sotien = Convert.ToInt32(TextBox2.Text);
        int balance = _balance.chuyenkhoan(senderid, password, receivername, sotien);
        if (balance >=0)
        {
            Label1.Text = balance.ToString();
            MultiView1.ActiveViewIndex = 1;
        }
        else if (balance == -2)
        {
            MultiView1.ActiveViewIndex = 3;
        }
        else
        {
            Label2.Text = _balance.getBalanceInfo(senderid).Tables[0].Rows[0]["BalanceUSD"].ToString();
            MultiView1.ActiveViewIndex = 2;
        }
    }
}
